package com.wanchuang.shengfubao.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;

import com.wanchuang.shengfubao.R;
import com.wanchuang.shengfubao.module.machines.AllowSnListBean;
import com.wanchuang.shengfubao.view.easyadapter.BaseViewHolder;
import com.wanchuang.shengfubao.view.easyadapter.RecyclerArrayAdapter;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 文件名 : SnCodeAdapter
 * 创建者 : MangoWang
 * 创建日期 : 2019/11/26 15:43
 * 微信 : MangoWaWang
 * 邮箱 : 763482205@qq.com
 * 描述 : TODO
 */
public class SnCodeAdapter extends RecyclerArrayAdapter<AllowSnListBean.SnMessage> {


    public SnCodeAdapter(Context context) {
        super(context);

    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(getContext()).inflate(R.layout.item_sn_code, parent, false));
    }

    class ViewHolder extends BaseViewHolder<AllowSnListBean.SnMessage> {
        @BindView(R.id.tv_sn_code)
        TextView tvSnCode;
        @BindView(R.id.cb_check)
        CheckBox cbCheck;
        @BindView(R.id.tv_no_use)
        TextView tvNoUse;


        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void setData(AllowSnListBean.SnMessage data) {
            tvSnCode.setText(data.getSn_code());
            if (data.getIs_transfer().equals("0")) {
                tvNoUse.setVisibility(View.GONE);
                cbCheck.setVisibility(View.VISIBLE);
                tvSnCode.setTextColor(Color.parseColor("#FF676E7D"));
                if (data.isSelect()) {
                    cbCheck.setChecked(true);
                } else {
                    cbCheck.setChecked(false);
                }
            } else {
                tvNoUse.setVisibility(View.VISIBLE);
                cbCheck.setVisibility(View.GONE);
                tvSnCode.setTextColor(Color.parseColor("#FFB0B6C4"));
            }
        }
    }
}